function ROM () 
{
    this.VERTICAL_MIRRORING = 0,
    this.HORIZONTAL_MIRROING = 1,
    this.FOURSCREEN_MIRRORING = 2,
    this.SINGLESCREEN_MIRRORING = 3,
    this.SINGLESCREEN_MIRRORING2 = 4,
    this.SINGLESCREEN_MIRRORING3 = 5,
    this.SINGLESCREEN_MIRRORING4 = 6,
    this.CHRROM_MIRRORING = 7,

    this.header = [],
    this.rom = [],
    this.vrom = [],
    // TODO= tiles

    this.romCount = 0,
    this.vromCount = 0,
    this.mirroring = 0,
    this.mapper = 0,

    this.init = function (nes)
    {
	dumpCode(nes);
	// header
	this.header = new Array(16);
	var i;
	var j;
	for(i=0;i<16;i++) 
	{
	    this.header[i]=nes.charCodeAt(i);
	};

	// check valid
	var nes_header = nes.slice(0,3);
	var nes_tag = nes.charCodeAt(3);
	if(!((nes_header == "NES") && (nes_tag== 0x1A)))
	{
	    alert("invalid ROM header:"+nes_header+nes_tag);
	    return;
	};
	
	this.romCount = nes.charCodeAt(4);
	this.vromCount = nes.charCodeAt(5)*2;
	if (((nes.charCodeAt(6)) & 1) != 0)
	{
	    this.mirroring = 1;
	} 
	else  
	{
	    this.mirroring = 0;
	};
	this.mapper = (nes.charCodeAt(6) >> 4) | (nes.charCodeAt(7) & 0xF0);
	dumpRomInfo(this);

	for(i =0;i<this.romCount;i++)
	{
	    this.rom.push(new Array(16384));
	};

	for(i=0;i<this.vromCount;i++)
	{
	    this.vrom.push(new Array(4096));
	};
	// TODO = tile

	// Load PRG-ROM
	var offset = 16;
	for(i=0;i<this.romCount;i++)
	{
	    for(j=0;j<16384;j++)
	    {
		((this.rom)[i])[j] = nes.charCodeAt(offset+j);
	    };
	    offset += 16384;
	};

	// Load CHR-ROM
	for(i=0;i<this.vromCount;i++)
	{
	    for(j=0;j<4096;j++)
	    {
		((this.vrom)[i])[j] = nes.charCodeAt(offset+j);
	    };
	    offset += 4096;
	};
	

	// TODO = Load Tile


    };

 
};


